package com.heima.schedule.feign;

import com.heima.apis.schedule.IScheduleClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.schedule.dots.Task;
import com.heima.schedule.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ScheduleClient implements IScheduleClient {

    @Autowired
    private TaskService taskService ;

    @PostMapping("/api/v1/task/add")
    @Override
    public ResponseResult addTask(@RequestBody Task task) {
        long l = taskService.addTask(task);
        return ResponseResult.okResult(l);
    }

    @GetMapping("/api/v1/task/{taskId}")
    @Override
    public ResponseResult cancelTask(@PathVariable("taskId") Long taskId) {
        boolean b = taskService.cancelTask(taskId);
        return ResponseResult.okResult(b);
    }


    @GetMapping("/api/v1/task/{type}/{priority}")
    @Override
    public ResponseResult pullTask(@PathVariable("type") Integer type, @PathVariable("priority")Integer priority) {
        Task task = taskService.pullTask(type, priority);
        return ResponseResult.okResult(task);
    }
}
